/* eslint valid-jsdoc: "off" */

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = (exports = {});

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1712338258976_4976";

  // add your middleware config here
  config.middleware = [];

  // 异常处理
  config.onerror = {
    accepts: () => {
      return "json";
    },
    json: (err, ctx) => {
      console.log(err);
      ctx.body = {
        code: err.status,
        success: false,
        error: err.errors[0].message,
        field: err.errors[0].field,
      };
      ctx.status = err.status;
    },
  };

  // 连接数据库
  config.mongoose = {
    // url: 'mongodb://username:password@localhost:27017/database_name'
    url: "mongodb://chabaidao:kn3ALYA32n7FAnFa@42.193.231.115:27017/chabaidao",
  };
  // 参数校验
  config.validate = {
    convert: true, //允许参数类型转换
    // validateRoot: false,
  };
  // 配置jwt
  config.jwt = {
    secret: "Jay",
    expiresIn: "30d",
  };
  // 地图信息
  config.map = {
    key: "WOKBZ-TKNKN-X2MF5-SGVXY-TOLKF-SABEH",
  };
  // 微信小程序信息
  config.wx = {
    appid: "wx044fc84fdfe9194f",
    secret: "17069b0fe106d873ae85ebafd1f15891",
    mchid: "1650931274",//商户号
    serial_no: "46AEF994822319126475DA3F041ED32F070006FF",//证书序列号
    wxKeyV3: "xuexiruheyindaowodepeixunxueyuan",//v3密钥
  };

  // 跨域
  config.cors = {
    origin: "*",
    allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH",
  };
  // 文件上传
  config.multipart = {
    fileSize: "1000mb",
    mode: "file",
  };
  // 腾讯云存储桶
  config.cos = {
    SecretId: "AKIDITi7a7mbcmxiT9zolil0BUoJtaTE8yaS", // 推荐使用环境变量获取；用户的 SecretId，建议使用子账号密钥，授权遵循最小权限指引，降低使用风险。子账号密钥获取可参考https://cloud.tencent.com/document/product/598/37140
    SecretKey: "IZqNxX6bzBGNa0VG5pXK0gIvPrR7jK0E", // 推荐使用环境变量获取；用户的 SecretKey，建议使用子账号密钥，授权遵循最小权限指引，降低使用风险。子账号密钥获取可参考https://cloud.tencent.com/document/product/598/37140
    Bucket: "bucket-chabaidao-1308160773",
    Region: "ap-guangzhou",
    prefix: "img/",
  };
  config.io = {
    config: {}, // 传递给 engine.io
    cors:true,
    namespace: {
      "/": {
        connectionMiddleware: ["connection"],
        packetMiddleware: [],
      },
    },
  };

  // 取消csrf安全防范
  config.security = {
    csrf: {
      enable: false,
    },
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };
};
